/**
 * Copyright (c) 2011 Nokia Corporation.
 */

#ifndef FILEMODEL_H
#define FILEMODEL_H

// Qt includes
#include <QAbstractListModel>
#include <QFile>
#include <QFileInfo>
#include <QList>


class FileModel : public QAbstractListModel
{
    Q_OBJECT

public: // Data types

    enum FileModelRoles {
        TypeRole = Qt::UserRole + 1,
        NameRole,
        SizeRole,
        StatusRole
    };

    enum FileType {
        Directory = 0,
        File
    };

    enum Status {
        None = 0,
        MarkedToBeBackedUp,
        MarkedToBeRemoved,
        BackedUp,
        ContainsMarkedToBeBackedUp, // Only for folders
        ContainsMarkedToBeRemoved // Only for folders
    };

public:
    explicit FileModel(QObject *parent = 0);
    virtual ~FileModel();

public: // From QAbstractListModel
    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
    int rowCount(const QModelIndex &parent = QModelIndex()) const;
    void removeRow(int row, const QModelIndex &parent);

public:
    void appendFile(QFile &file, Status status = None);
    void appendFile(QFileInfo &fileInfo, Status status = None);
    void setFiles(QFileInfoList fileInfoList);
    QFileInfoList &files();
    bool getFileInfo(int index, QFileInfo &fileInfo) const;
    void setFileStatus(int index, Status status);
    void setFileStatuses(QMap<int, Status> &statuses);
    Status fileStatus(int index) const;

public slots:
    void clear();
    void clearFileStatuses();

private: // Data
    QFileInfoList m_files;
    QMap<int, Status> m_fileStatuses;
    bool m_foldersOnly;
};

Q_DECLARE_METATYPE(FileModel::FileType)


#endif // FILEMODEL_H

// End of file.
